package utils

import (
	"crypto/aes"
	"crypto/cipher"
	"encoding/base64"
)

// EncryptAESCFB 使用CFB模式对输入的字符串进行AES加密
func EncryptAESCFB(plaintext string, keyStr string) (string, error) {
	block, err := aes.NewCipher([]byte(keyStr))
	if err != nil {
		return "", err
	}
	iv := []byte(keyStr)
	stream := cipher.NewCFBEncrypter(block, iv)
	ciphertext := make([]byte, len(plaintext))
	stream.XORKeyStream(ciphertext, []byte(plaintext))
	base64Ciphertext := base64.StdEncoding.EncodeToString(ciphertext)
	return base64Ciphertext, nil
}

func Base64Encode(plaintext string) string {
	base64Ciphertext := base64.StdEncoding.EncodeToString([]byte(plaintext))
	return base64Ciphertext
}
